package cn.kgc.controller;

import cn.kgc.pojo.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @GetMapping("/set/{key}/{value}")
    public String set(@PathVariable("key") String key,@PathVariable("value") String value){
        redisTemplate.opsForValue().set(key,value);
        return "ok";
    }

    @GetMapping("/get/{key}")
    public Object get(@PathVariable("key") String key){
        return redisTemplate.opsForValue().get(key);
    }

    @PostMapping("/emp")
    public String addEmp(Emp emp){
        redisTemplate.opsForValue().set("emp:"+emp.getId(),emp);
        return "ok";
    }
}
